Skip to main content

Returning booleans

It's unnecessary to use if and else when returning a boolean (true or false).

For example,

function toVote(age) {
if (age >= 18) {
return true;
} else {
return false;
}
}

ispassing(66);

The same code can be written like,

function toVote(age) {
return age >= 50;
}

ispassing(35);
Note

without using if/else, which always returns a boolean!

This only works when returning a boolean from a function.